from django.db import models
from django.utils import timezone


class Tier2FuncInfo(models.Model):
    """
    功能用例执行结果详情表，数据来源yat_log，按用例入库
    """
    id = models.AutoField(primary_key=True)
    run_os = models.CharField(max_length=15)
    model_name = models.CharField(max_length=100)
    tc_name = models.CharField(max_length=100)
    run_result = models.CharField(max_length=2)
    start_time = models.DateTimeField()
    run_time = models.CharField(max_length=20)
    failed_reason = models.CharField(max_length=3000, null=True, blank=True,
                                     default='暂无')
    solution = models.CharField(max_length=1000, null=True, blank=True,
                                default='暂无')
    problem_type = models.CharField(max_length=20, default='用例问题')
    issue_no = models.CharField(max_length=100, null=True, blank=True)
    develop_owner = models.CharField(max_length=20, null=True, blank=True)
    test_owner = models.CharField(max_length=20, null=True, blank=True)
    status = models.CharField(max_length=10, default='未解决')
    ip_name = models.CharField(max_length=20)
    jenkins_link = models.URLField(null=True, blank=True)
    end_time = models.DateField(default=timezone.now)
    log_link = models.URLField(null=True, blank=True)


class Tier2FuncModel(models.Model):
    """
    功能用例执行结果模块表，数据来源yat_log，按模块入库
    """
    id = models.AutoField(primary_key=True)
    run_os = models.CharField(max_length=15)
    model_name = models.CharField(max_length=100)
    total_num = models.IntegerField()
    pass_num = models.IntegerField()
    fail_num = models.IntegerField()
    block_num = models.IntegerField()
    start_time = models.DateTimeField()
    run_time = models.TimeField()
    ip_name = models.CharField(max_length=20)
    core_num = models.IntegerField(default=0)


class Tier2FuncOs(models.Model):
    """
    功能用例执行结果模块表，数据来源表FuncModel，统计入库
    """
    id = models.AutoField(primary_key=True)
    run_os = models.CharField(max_length=15)
    total_num = models.IntegerField()
    pass_num = models.IntegerField()
    fail_num = models.IntegerField()
    block_num = models.IntegerField()
    start_time = models.DateTimeField()
    run_time = models.CharField(max_length=20)


class Tier3FuncInfo(models.Model):
    """
    功能用例执行结果详情表，数据来源yat_log，按用例入库
    """
    id = models.AutoField(primary_key=True)
    run_os = models.CharField(max_length=15)
    model_name = models.CharField(max_length=100)
    tc_name = models.CharField(max_length=100)
    run_result = models.CharField(max_length=2)
    start_time = models.DateTimeField()
    run_time = models.CharField(max_length=20)
    failed_reason = models.CharField(max_length=3000, null=True, blank=True,
                                     default='暂无')
    solution = models.CharField(max_length=1000, null=True, blank=True,
                                default='暂无')
    problem_type = models.CharField(max_length=20, default='用例问题')
    issue_no = models.CharField(max_length=100, null=True, blank=True)
    develop_owner = models.CharField(max_length=20, null=True, blank=True)
    test_owner = models.CharField(max_length=20, null=True, blank=True)
    status = models.CharField(max_length=10, default='未解决')
    ip_name = models.CharField(max_length=20)
    jenkins_link = models.URLField(null=True, blank=True)
    end_time = models.DateField(default=timezone.now)
    log_link = models.URLField(null=True, blank=True)


class Tier3FuncModel(models.Model):
    """
    功能用例执行结果模块表，数据来源yat_log，按模块入库
    """
    id = models.AutoField(primary_key=True)
    run_os = models.CharField(max_length=15)
    model_name = models.CharField(max_length=100)
    total_num = models.IntegerField()
    pass_num = models.IntegerField()
    fail_num = models.IntegerField()
    block_num = models.IntegerField()
    start_time = models.DateTimeField()
    run_time = models.TimeField()
    ip_name = models.CharField(max_length=20)
    core_num = models.IntegerField(default=0)


class Tier3FuncOs(models.Model):
    """
    功能用例执行结果模块表，数据来源表FuncModel，统计入库
    """
    id = models.AutoField(primary_key=True)
    run_os = models.CharField(max_length=15)
    total_num = models.IntegerField()
    pass_num = models.IntegerField()
    fail_num = models.IntegerField()
    block_num = models.IntegerField()
    start_time = models.DateTimeField()
    run_time = models.CharField(max_length=20)


class MasFuncInfo(models.Model):
    """
    功能用例执行结果详情表，数据来源yat_log，按用例入库
    """
    id = models.AutoField(primary_key=True)
    run_os = models.CharField(max_length=15)
    model_name = models.CharField(max_length=100)
    tc_name = models.CharField(max_length=100)
    run_result = models.CharField(max_length=2)
    start_time = models.DateTimeField()
    run_time = models.CharField(max_length=20)
    failed_reason = models.CharField(max_length=3000, null=True, blank=True,
                                     default='暂无')
    solution = models.CharField(max_length=1000, null=True, blank=True,
                                default='暂无')
    problem_type = models.CharField(max_length=20, default='用例问题')
    issue_no = models.CharField(max_length=100, null=True, blank=True)
    develop_owner = models.CharField(max_length=20, null=True, blank=True)
    test_owner = models.CharField(max_length=20, null=True, blank=True)
    status = models.CharField(max_length=10, default='未解决')
    ip_name = models.CharField(max_length=20)
    jenkins_link = models.URLField(null=True, blank=True)
    end_time = models.DateField(default=timezone.now)
    log_link = models.URLField(null=True, blank=True)


class MasFuncModel(models.Model):
    """
    功能用例执行结果模块表，数据来源yat_log，按模块入库
    """
    id = models.AutoField(primary_key=True)
    run_os = models.CharField(max_length=15)
    model_name = models.CharField(max_length=100)
    total_num = models.IntegerField()
    pass_num = models.IntegerField()
    fail_num = models.IntegerField()
    block_num = models.IntegerField()
    start_time = models.DateTimeField()
    run_time = models.TimeField()
    ip_name = models.CharField(max_length=20)
    core_num = models.IntegerField(default=0)


class MasFuncOs(models.Model):
    """
    功能用例执行结果模块表，数据来源表FuncModel，统计入库
    """
    id = models.AutoField(primary_key=True)
    run_os = models.CharField(max_length=15)
    total_num = models.IntegerField()
    pass_num = models.IntegerField()
    fail_num = models.IntegerField()
    block_num = models.IntegerField()
    start_time = models.DateTimeField()
    run_time = models.CharField(max_length=20)


class ReliaInfo(models.Model):
    """
    可靠性用例执行结果详情表，数据来源yat_log，按用例入库
    """
    id = models.AutoField(primary_key=True)
    run_os = models.CharField(max_length=15)
    model_name = models.CharField(max_length=100)
    tc_name = models.CharField(max_length=100)
    run_result = models.CharField(max_length=2)
    start_time = models.DateTimeField()
    run_time = models.CharField(max_length=20)
    failed_reason = models.CharField(max_length=3000, null=True, blank=True,
                                     default='暂无')
    solution = models.CharField(max_length=1000, null=True, blank=True,
                                default='暂无')
    problem_type = models.CharField(max_length=20, default='用例问题')
    issue_no = models.CharField(max_length=100, null=True, blank=True)
    develop_owner = models.CharField(max_length=20, null=True, blank=True)
    test_owner = models.CharField(max_length=20, null=True, blank=True)
    status = models.CharField(max_length=10, default='未解决')
    ip_name = models.CharField(max_length=20)
    jenkins_link = models.URLField(null=True, blank=True)
    end_time = models.DateField(default=timezone.now)
    log_link = models.URLField(null=True, blank=True)


class ReliaModel(models.Model):
    """
    可靠性用例执行结果模块表，数据来源yat_log，按模块入库
    """
    id = models.AutoField(primary_key=True)
    run_os = models.CharField(max_length=15)
    model_name = models.CharField(max_length=100)
    total_num = models.IntegerField()
    pass_num = models.IntegerField()
    fail_num = models.IntegerField()
    block_num = models.IntegerField()
    start_time = models.DateTimeField()
    run_time = models.TimeField()
    ip_name = models.CharField(max_length=20)
    core_num = models.IntegerField(default=0)


class ReliaOs(models.Model):
    """
    可靠性用例执行结果模块表，数据来源表FuncModel，统计入库
    """
    id = models.AutoField(primary_key=True)
    run_os = models.CharField(max_length=15)
    total_num = models.IntegerField()
    pass_num = models.IntegerField()
    fail_num = models.IntegerField()
    block_num = models.IntegerField()
    start_time = models.DateTimeField()
    run_time = models.CharField(max_length=20)


class HisTier2FuncInfo(models.Model):
    """
    功能用例执行结果详情历史表
    """
    id = models.AutoField(primary_key=True)
    run_os = models.CharField(max_length=15)
    model_name = models.CharField(max_length=100)
    tc_name = models.CharField(max_length=100)
    run_result = models.CharField(max_length=2)
    start_time = models.DateTimeField()
    run_time = models.CharField(max_length=20)
    failed_reason = models.CharField(max_length=3000, null=True, blank=True,
                                     default='暂无')
    solution = models.CharField(max_length=1000, null=True, blank=True,
                                default='暂无')
    problem_type = models.CharField(max_length=20, default='用例问题')
    issue_no = models.CharField(max_length=100, null=True, blank=True)
    develop_owner = models.CharField(max_length=20, null=True, blank=True)
    test_owner = models.CharField(max_length=20, null=True, blank=True)
    status = models.CharField(max_length=10, default='未解决')
    ip_name = models.CharField(max_length=20)
    jenkins_link = models.URLField(null=True, blank=True)
    end_time = models.DateField(default=timezone.now)
    log_link = models.URLField(null=True, blank=True)


class HisTier2FuncModel(models.Model):
    """
    功能用例执行结果模块历史表
    """
    id = models.AutoField(primary_key=True)
    run_os = models.CharField(max_length=15)
    model_name = models.CharField(max_length=100)
    total_num = models.IntegerField()
    pass_num = models.IntegerField()
    fail_num = models.IntegerField()
    block_num = models.IntegerField()
    start_time = models.DateTimeField()
    run_time = models.TimeField()
    ip_name = models.CharField(max_length=20)
    core_num = models.IntegerField(default=0)


class HisTier2FuncOs(models.Model):
    """
    功能用例执行结果模块历史表
    """
    id = models.AutoField(primary_key=True)
    run_os = models.CharField(max_length=15)
    total_num = models.IntegerField()
    pass_num = models.IntegerField()
    fail_num = models.IntegerField()
    block_num = models.IntegerField()
    start_time = models.DateTimeField()
    run_time = models.CharField(max_length=20)


class HisTier3FuncInfo(models.Model):
    """
    功能用例执行结果详情历史表
    """
    id = models.AutoField(primary_key=True)
    run_os = models.CharField(max_length=15)
    model_name = models.CharField(max_length=100)
    tc_name = models.CharField(max_length=100)
    run_result = models.CharField(max_length=2)
    start_time = models.DateTimeField()
    run_time = models.CharField(max_length=20)
    failed_reason = models.CharField(max_length=3000, null=True, blank=True,
                                     default='暂无')
    solution = models.CharField(max_length=1000, null=True, blank=True,
                                default='暂无')
    problem_type = models.CharField(max_length=20, default='用例问题')
    issue_no = models.CharField(max_length=100, null=True, blank=True)
    develop_owner = models.CharField(max_length=20, null=True, blank=True)
    test_owner = models.CharField(max_length=20, null=True, blank=True)
    status = models.CharField(max_length=10, default='未解决')
    ip_name = models.CharField(max_length=20)
    jenkins_link = models.URLField(null=True, blank=True)
    end_time = models.DateField(default=timezone.now)
    log_link = models.URLField(null=True, blank=True)


class HisTier3FuncModel(models.Model):
    """
    功能用例执行结果模块历史表
    """
    id = models.AutoField(primary_key=True)
    run_os = models.CharField(max_length=15)
    model_name = models.CharField(max_length=100)
    total_num = models.IntegerField()
    pass_num = models.IntegerField()
    fail_num = models.IntegerField()
    block_num = models.IntegerField()
    start_time = models.DateTimeField()
    run_time = models.TimeField()
    ip_name = models.CharField(max_length=20)
    core_num = models.IntegerField(default=0)


class HisTier3FuncOs(models.Model):
    """
    功能用例执行结果模块历史表
    """
    id = models.AutoField(primary_key=True)
    run_os = models.CharField(max_length=15)
    total_num = models.IntegerField()
    pass_num = models.IntegerField()
    fail_num = models.IntegerField()
    block_num = models.IntegerField()
    start_time = models.DateTimeField()
    run_time = models.CharField(max_length=20)


class HisMasFuncInfo(models.Model):
    """
    功能用例执行结果详情历史表
    """
    id = models.AutoField(primary_key=True)
    run_os = models.CharField(max_length=15)
    model_name = models.CharField(max_length=100)
    tc_name = models.CharField(max_length=100)
    run_result = models.CharField(max_length=2)
    start_time = models.DateTimeField()
    run_time = models.CharField(max_length=20)
    failed_reason = models.CharField(max_length=3000, null=True, blank=True,
                                     default='暂无')
    solution = models.CharField(max_length=1000, null=True, blank=True,
                                default='暂无')
    problem_type = models.CharField(max_length=20, default='用例问题')
    issue_no = models.CharField(max_length=100, null=True, blank=True)
    develop_owner = models.CharField(max_length=20, null=True, blank=True)
    test_owner = models.CharField(max_length=20, null=True, blank=True)
    status = models.CharField(max_length=10, default='未解决')
    ip_name = models.CharField(max_length=20)
    jenkins_link = models.URLField(null=True, blank=True)
    end_time = models.DateField(default=timezone.now)
    log_link = models.URLField(null=True, blank=True)


class HisMasFuncModel(models.Model):
    """
    功能用例执行结果模块历史表
    """
    id = models.AutoField(primary_key=True)
    run_os = models.CharField(max_length=15)
    model_name = models.CharField(max_length=100)
    total_num = models.IntegerField()
    pass_num = models.IntegerField()
    fail_num = models.IntegerField()
    block_num = models.IntegerField()
    start_time = models.DateTimeField()
    run_time = models.TimeField()
    ip_name = models.CharField(max_length=20)
    core_num = models.IntegerField(default=0)


class HisMasFuncOs(models.Model):
    """
    功能用例执行结果模块历史表
    """
    id = models.AutoField(primary_key=True)
    run_os = models.CharField(max_length=15)
    total_num = models.IntegerField()
    pass_num = models.IntegerField()
    fail_num = models.IntegerField()
    block_num = models.IntegerField()
    start_time = models.DateTimeField()
    run_time = models.CharField(max_length=20)


class HisReliaInfo(models.Model):
    """
    可靠性用例执行结果详情历史表
    """
    id = models.AutoField(primary_key=True)
    run_os = models.CharField(max_length=15)
    model_name = models.CharField(max_length=100)
    tc_name = models.CharField(max_length=100)
    run_result = models.CharField(max_length=2)
    start_time = models.DateTimeField()
    run_time = models.CharField(max_length=20)
    failed_reason = models.CharField(max_length=3000, null=True, blank=True,
                                     default='暂无')
    solution = models.CharField(max_length=1000, null=True, blank=True,
                                default='暂无')
    problem_type = models.CharField(max_length=20, default='用例问题')
    issue_no = models.CharField(max_length=100, null=True, blank=True)
    develop_owner = models.CharField(max_length=20, null=True, blank=True)
    test_owner = models.CharField(max_length=20, null=True, blank=True)
    status = models.CharField(max_length=10, default='未解决')
    ip_name = models.CharField(max_length=20)
    jenkins_link = models.URLField(null=True, blank=True)
    end_time = models.DateField(default=timezone.now)
    log_link = models.URLField(null=True, blank=True)


class HisReliaModel(models.Model):
    """
    可靠性用例执行结果模块历史表
    """
    id = models.AutoField(primary_key=True)
    run_os = models.CharField(max_length=15)
    model_name = models.CharField(max_length=100)
    total_num = models.IntegerField()
    pass_num = models.IntegerField()
    fail_num = models.IntegerField()
    block_num = models.IntegerField()
    start_time = models.DateTimeField()
    run_time = models.TimeField()
    ip_name = models.CharField(max_length=20)
    core_num = models.IntegerField(default=0)


class HisReliaOs(models.Model):
    """
    可靠性用例执行结果模块历史表
    """
    id = models.AutoField(primary_key=True)
    run_os = models.CharField(max_length=15)
    total_num = models.IntegerField()
    pass_num = models.IntegerField()
    fail_num = models.IntegerField()
    block_num = models.IntegerField()
    start_time = models.DateTimeField()
    run_time = models.CharField(max_length=20)


class SteadyInfo(models.Model):
    """
    长稳表
    """
    run_os = models.CharField(max_length=15)
    start_time = models.DateTimeField()
    status = models.CharField(max_length=10, null=True, blank=True,
                              default='执行中')


class PerfInfo(models.Model):
    """
    性能表
    """
    cpu_feature = models.CharField(max_length=10)
    cluster = models.CharField(max_length=20)
    t_feature = models.CharField(max_length=20)
    start_time = models.DateTimeField()
    tpmc = models.DecimalField(max_digits=50, decimal_places=6)
    dot_res = models.TextField()


class DbVerison(models.Model):
    """
    数据库版本
    """
    feature = models.CharField(max_length=50)
    db_version = models.CharField(max_length=1000)
    install_time = models.DateTimeField()


class IssuesInfo(models.Model):
    """
    issues info, include issue ID, title, priority, creater, assignee, state and so on
    """
    issue_id = models.CharField(max_length=32, primary_key=True)
    category = models.CharField(max_length=128, blank=True, null=True)
    title = models.TextField()
    priority = models.CharField(max_length=32)
    di = models.FloatField(blank=False)
    creater = models.CharField(max_length=64)
    assignee = models.CharField(max_length=64, blank=True, null=True)
    link = models.CharField(max_length=256)
    state = models.CharField(max_length=64)
    create_date = models.DateTimeField()


class IssuesCategory(models.Model):
    """
    issue category, include task, bug, reuqirement
    """
    issue_category = models.CharField(max_length=32)
    issue_category_id = models.IntegerField()
    issue_count = models.IntegerField(default=0, blank=False)


class PerfCPU(models.Model):
    """
    tpcc use ration of CPU/IO/NET
    """
    cpu_core = models.CharField(max_length=20)
    us = models.DecimalField(max_digits=4, decimal_places=1)
    sy = models.DecimalField(max_digits=4, decimal_places=1)
    start_time = models.DateTimeField()


class SqlPerf(models.Model):
    """
    sql perf table, inclue exetime,date,sql_explain
    """
    sql_statement = models.CharField(max_length=5000)
    sql_explain = models.CharField(max_length=10000)
    exe_time = models.DecimalField(max_digits=50, decimal_places=2)
    thread_num = models.IntegerField()
    throughput = models.CharField(max_length=50, blank=True, default='-')
    start_time = models.DateTimeField()
    scene = models.CharField(max_length=20)
    db_type = models.CharField(max_length=20, default='openGauss')


class SqlPerfCommit(models.Model):
    """
    sql perf date and commit
    """
    start_time = models.DateTimeField()
    commit_id = models.CharField(max_length=20)
    scene = models.CharField(max_length=20)
    db_type = models.CharField(max_length=20, default='openGauss')


class TpchPerf(models.Model):
    """
    tpch perf table, include exec_date,tpch_res,queryplain
    """
    start_time = models.DateTimeField()
    sql_id = models.IntegerField()
    tpch_res = models.DecimalField(max_digits=10, decimal_places=2)
    explain = models.CharField(max_length=10000)
    db_type = models.CharField(max_length=20, default='openGauss')
    commit_id = models.CharField(max_length=20)
    query_dop = models.IntegerField()


class TpchInfo(models.Model):
    """
    tpch sql info table, include sql_statement,sql_explain
    """
    sql_id = models.IntegerField()
    sql_statement = models.CharField(max_length=1000)
    sql_explain = models.CharField(max_length=10000)


class MigratePerf(models.Model):
    """
    migrate perf info table
    """
    start_time = models.DateTimeField()
    commit_id = models.CharField(max_length=20)
    migrate_type = models.CharField(max_length=20)
    migrate_scene = models.CharField(max_length=20)
    db_type = models.CharField(max_length=20, default='openGauss')
    speed = models.IntegerField()